// 处理路径拼接
// handlerPathJion(['/a','/b','c'])
export const handlerPathJion = (paths) =>{
    let str = "";
    paths.forEach((item) => {
        const url = item.trim();
        if (url) {
        if (url.startsWith('/')) {
            str += url;
        } else {
            str += `/${url}`;
        }         
    }
 });
    return str;
};

// 处理api返回的图片路径
export const handlerPicPath =(pic,key ="pic") =>{
if (typeof pic === "string") {
    const p = pic.replace(/\\/g,"/").replace("public","");
    return import.meta.env.VITE_HOST_URL + p;
} else if (Array.isArray(pic)){
    return pic.map((item)=>{
        const res= {...item};
        const p = res[key].replace(/\\/g,"/").replace("public","");
        res[key] = import.meta.env.VITE_HOST_URL + p;
        return res;
    })
  }
  return pic;
};
export const parseUrl = (urlString) => {
    const url = new URL(urlString);
    return {
      protocol: url.protocol,
      host: url.host,
      hostname: url.hostname,
      port: url.port,
      pathname: url.pathname,
      search: url.search,
      hash: url.hash,
    };
  };
  
  // 获取后缀
  export const getSuffix = (url, str = ".") => {
    const arr = url.split(".");
    const a = arr.slice(0, -1).join(".");
    const b = "." + arr[arr.length - 1];
    return [a, b];
  };

